package com.CRApp.controller;

import com.CRApp.pojo.Result;
import com.CRApp.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @ClassName: FileUploadController
 * @Author : LuoFan洛樊
 * @Date : 2025/2/7 - 16:07
 * Description : TODO
 */
@RestController
public class FileUploadController {

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        //保证文件名字唯一，防止文件覆盖  使用uuid
        String filename = UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
//        file.transferTo(new File("E:\\CatRecognitionAPP\\CR_App_back\\CatRecognitionAPP\\img\\" + filename));
        String url = AliOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success(url);
    }
}
